<!DOCTYPE html>
<html>

<head lang="en">
    <title>旅游视频</title>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.css">
    <script src="/js/jquery/jquery.min.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css" />
    <link rel="stylesheet" href="/css/reset.css" />
    <link rel="stylesheet" href="/css/strategyComment.css" />
    <script src="/js/plugins/jrender/jrender.js"></script>
    <link rel="stylesheet" href="/js/plugins/jquery-confirm/css/jquery-confirm.css">
    <script src="/js/plugins/jquery-confirm/js/jquery-confirm.js"></script>
    <script src="/js/plugins/jquery-form/jquery.form.js"></script>
    <script src="/js/plugins/hivideo-master/hivideo.js"></script>
    <link rel="stylesheet" href="/js/plugins/hivideo-master/assets/hivideo.css">
    <script src="/js/common.js"></script>
    <style>
        .videoBox{
            position: relative;
            width: 340px;
            height: 240px;
        }
        .videoBox video{
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
            max-width: 100%;
            max-height: 100%;
            outline: 1px solid #000;
        }
        .container{
            margin-bottom:35%
        }
    </style>
</head>

<body>
<div class="search-head">
    <div class="row nav-search">
        <div class="col">
            <a href="javascript:window.history.go(-1)">
                <span><i class="fa fa-chevron-left" ></i></span>
            </a>

        </div>
        <div class="col">
            <span>添加你的视频</span>
        </div>
        <div class="col"></div>
    </div>
</div>
    <div>
        <p>添加视频标题</p>
        <input id="title" class="form-control"  placeholder="请使用文明用语,不做标题党!!"   />

        <p>视频简介</p>
        <textarea id="subTitle" class="form-control" rows="5" placeholder="请填写你对该旅游地的评价"></textarea>
        <p>视频封面</p>
        <img id="coverUrl" width="100%" height="200px" src="/upload/Snipaste_2018-11-17_09-30-18.png"/>
        <button type="button" class="btn" id="changeBtn">
            <i class="fa fa-pencil-square-o"></i>
            <small>更换封面</small>
        </button>
    </div>
<div class="cover">
</div>
    <div class="container">
        <p>上传视频</p>
        <button type="button" class="btn btn-danger upvideo">点击上传</button>
        <div class="row">
            <form id="videoForm" method="post" enctype="multipart/form-data" action="/images/video">
                <input type="file" style="display: none" name="vid"/>
            </form>
            <form id="imgForm" action="/images" method="post" enctype="multipart/form-data">
                <input type="file" name="pic" style="display: none;" accept="image/*"/>
            </form>
            <div class="col-5 rect">
                <li class="videoBox">
                    <video  width="100%" height="100%" controls="controls"
                            class="myVideo" style="display: none">
                    </video>
                </li>
            </div>
        </div>

    </div>

</div>



<div class="operation">
    <button class="btn" onclick="window.history.go(-1)">放弃提交</button>
    <button class="btn" id="submitBtn">提交视频</button>
</div>

<div id="push"></div>
</body>
<script>
    var user = sessionStorage.getItem("user");
    user = JSON.parse(user);
    var imgSelect;
    var videoSelect;
    var imgUrl = "/upload/Snipaste_2018-11-17_09-30-18.png";
    var vidUrl;
    $(function () {
        imgSelect = $("#imgForm input[name='pic']");
        videoSelect = $("#videoForm input[name='vid']");
        $(".upvideo").click(function () {
            videoSelect.val("");
            videoSelect.click();
        });
        $("#changeBtn").click(function () {
            imgSelect.val("");
            imgSelect.click();
        })
        $("#videoForm input[name='vid']").change(function () {
            if (videoSelect.val()){
                $("#videoForm").ajaxSubmit(function (data) {
                    vidUrl = data.url;
                    $(".myVideo").attr("src",data.url);
                    $(".myVideo").css("display","");
                    $(".upvideo").css("display","none");
                })
            }
        });
        $("#imgForm input[name='pic']").change(function () {
            if (imgSelect.val()){
                $("#imgForm").ajaxSubmit(function (data) {
                    imgUrl = data.url;
                    $("#coverUrl").attr("src",data.url);
                })
            }
        });
        $("#submitBtn").click(function () {
            if (user) {
                $.post("/videos", {
                    "user.id": user.id,
                    title: $("#title").val(),
                    subTitle: $("#subTitle").val(),
                    imgUrl: imgUrl,
                    vidUrl: vidUrl
                }, function (data) {
                    location.href = "/mine/myVideo.html";
                })
            }else {
                location.href = "/login.html";
            }
        })
    });

</script>

</html>